package acwing._2LanQiao._6DoublePointer_BFS_Graph;
/**
 * @Project : ProgrammingExercises
 * @Package : ACWing._2LanQiao._6DoublePointer_BFS_Graph
 * @File : Q1096.java
 * @Author : WangRuoyu
 * @Date : 2023/3/19 15:26
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

public class Q1096 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line = br.readLine();

        while (!"0 0 0".equals(line)) {
            String[] words = line.split(" ");
            int m = Integer.parseInt(words[0]);
            int n = Integer.parseInt(words[1]);
            int l = Integer.parseInt(words[2]);

            boolean[][][] visited = new boolean[m][n][l];

            int[] start = {};
            int[] end = {};

            for (int i = 0; i < m; ++i) {
                for (int j = 0; j < n; ++j) {
                    line = br.readLine();
                    for (int k = 0; k < l; ++k) {
                        if (line.charAt(k) == '#') {
                            visited[i][j][k] = true;
                        } else if (line.charAt(k) == 'S') {
                            start = new int[]{i, j, k, 0};
                            visited[i][j][k] = true;
                        } else if (line.charAt(k) == 'E') {
                            end = new int[]{i, j, k};
                        }
                    }
                }
                line = br.readLine();
            }

            Queue<int[]> q = new LinkedList<>();
            q.add(start);
            boolean flag = false;

            while (!q.isEmpty()) {
                int[] node = q.poll();
                int x = node[0];
                int y = node[1];
                int z = node[2];
                if (x == end[0] && y == end[1] && z == end[2]) {
                    System.out.printf("Escaped in %d minute(s).\n", node[3]);
                    flag = true;
                    break;
                }
                if (x > 0 && !visited[x - 1][y][z]) {
                    q.add(new int[]{x - 1, y, z, node[3] + 1});
                    visited[x - 1][y][z] = true;
                }
                if (x < m - 1 && !visited[x + 1][y][z]) {
                    q.add(new int[]{x + 1, y, z, node[3] + 1});
                    visited[x + 1][y][z] = true;
                }
                if (y < n - 1 && !visited[x][y + 1][z]) {
                    q.add(new int[]{x, y + 1, z, node[3] + 1});
                    visited[x][y + 1][z] = true;
                }
                if (y > 0 && !visited[x][y - 1][z]) {
                    q.add(new int[]{x, y - 1, z, node[3] + 1});
                    visited[x][y - 1][z] = true;
                }
                if (z > 0 && !visited[x][y][z - 1]) {
                    q.add(new int[]{x, y, z - 1, node[3] + 1});
                    visited[x][y][z - 1] = true;
                }
                if (z < l - 1 && !visited[x][y][z + 1]) {
                    q.add(new int[]{x, y, z + 1, node[3] + 1});
                    visited[x][y][z + 1] = true;
                }
            }

            if (!flag) {
                System.out.println("Trapped!");
            }

            line = br.readLine();
        }
    }
}

//3 4 5
//S....
//.###.
//.##..
//###.#
//#####
//#####
//##.##
//##...
//#####
//#####
//#.###
//####E
//1 3 3
//S##
//#E#
//###
//0 0 0